package com.scuec.groupfive.Controller;

import com.github.pagehelper.PageInfo;
import com.scuec.groupfive.entity.vo.UserPostVO;
import com.scuec.groupfive.service.UserPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/user/post")
public class UserPostController {

    @Autowired
    private UserPostService userPostService;

    /**
     * 根据用户ID分页查询收藏的帖子
     *
     * @param userId  用户ID
     * @param current 当前页
     * @param size    每页大小
     * @return 包含帖子信息和收藏信息的集合
     */
    // http://localhost:8080/user/post/favorites/12
    @GetMapping("/favorites/{userId}")
    public PageInfo<UserPostVO> getFavoritesByUserId(
            @PathVariable Long userId,
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "50") Integer size) {
        return userPostService.getFavoritesByUserId(userId, current, size);
    }

    /**
     * 删除收藏记录
     *
     * @param favoriteId 收藏ID
     * @return 操作结果
     */
    //localhost:8080/user/post/favorites/13
    @DeleteMapping("/favorites/{favoriteId}")
    public boolean deleteFavorite(@PathVariable Long favoriteId) {
        return userPostService.deleteFavorite(favoriteId);
    }
}